<?php
/**
 * Created by PhpStorm.
 * User: lhl
 * Date: 2020/12/15
 * Time: 14:48
 * Features:错误日志
 */

namespace app\api\validate;


use think\Validate;

class ErrorLogValidate extends Validate
{
    protected $rule = [
        'data' => 'require|array',
        'data.source' => 'require|in:1,2',
        'hostid' => 'integer|egt:1',//特殊必传
        'data.logid' => 'integer|egt:0',
        'data.name' => 'require',
        'data.time' => 'require|integer',
        'data.message' => 'require',
        'data.ip' => 'ip', //特殊必传
    ];

    /**
     * 场景单独验证: 客户端错误上传
     */
    public function sceneClientUpload()
    {
        //逗号隔开的字符串
        return $this->only([
            'data','data.source','hostid','data.logid','data.name','data.time','data.message','data.ip'
        ])->append('hostid','require');
    }

    /**
     * 场景单独验证: 中间件错误上传等其他场景
     */
    public function sceneMiddlewareUpload()
    {
        //逗号隔开的字符串
        return $this->only([
            'data','data.source','hostid','data.logid','data.name','data.time','data.message','data.ip'
        ])->append('data.ip','require');
    }

}